%% ----------------------------------------------------------------
%% Thesis.tex -- MAIN FILE (the one that you compile with LaTeX)
%% ---------------------------------------------------------------- 

% Set up the document
\documentclass[a4paper,11pt,oneside]{Thesis}  % Use the "Thesis" style, based on the ECS Thesis style by Steve Gunn
\graphicspath{{Figures/}}  % Location of the graphics files (set up for graphics to be in PDF format)

% Include any extra LaTeX packages required
\usepackage[square, numbers, comma, sort&compress]{natbib}  % Use the "Natbib" style for the references in the Bibliography
\usepackage{verbatim}  % Needed for the "comment" environment to make LaTeX comments
\usepackage[final]{pdfpages} % Allows for importing of pdfs
\usepackage{listings} % Alows for code inclusions
\usepackage{float} % Float control for figures, tables, etc.
\usepackage[section]{placeins} % Fine-grain float placement control for float barriers

% Package and environment configuration
\lstset{language=c,breaklines=true,tabsize=3,aboveskip=1em,float=tbph} % Configure the Listings module for C code by default
\hypersetup{urlcolor=black, colorlinks=true}  % Colours hyperlinks in black to avoid distractions.
\setcounter{tocdepth}{2} % Only show Chapters, sections and sub-sections in the Table of Contents (no deeper nested sections)

% Fix List of Listings page so there is a space between each chapter's listings
\makeatletter
\let\my@chapter\@chapter
\renewcommand*{\@chapter}
{
  \addtocontents{lol}{\protect\addvspace{10pt}}
  \my@chapter
}
\makeatother

% Custom command definitions
\newcommand{\superscript}[1]{\ensuremath{^{\textrm{#1}}}}
\newcommand{\subscript}[1]{\ensuremath{_{\textrm{#1}}}}

\begin{document}
%% ----------------------------------------------------------------
\frontmatter	  % Begin Roman style (i, ii, iii, iv...) page numbering

% Set up the Title Page
\title        {Embedded Bluetooth Stack}
\authors      {\texorpdfstring{\href{mailto:dean@fourwalledcubicle.com}{Dean Camera}} {Dean Camera}}
\addresses    {\groupname\\\deptname\\\univname}  % Do not change this here, instead these must be set in the "Thesis.cls" file, please look through it instead
\authordegree {Bachelor of Computer Science/ \\ Bachelor of Electronics Engineering}
\thesistype   {Undergraduate Thesis}
\date         {\today}
\subject      {}
\keywords     {}
\supervisor   {Prof. John Devlin}
\cosupervisor {Robert Ross}

\maketitle
%% ----------------------------------------------------------------
\setstretch{1.3}  % It is better to have smaller font and larger line spacing than the other way round

% Define the page headers using the FancyHdr package and set up for one-sided printing
\fancyhead{}  % Clears all page headers and footers
\rhead{\thepage}  % Sets the right side header to show the page number
\lhead{}  % Clears the left side page header
\pagestyle{fancy}  % Finally, use the "fancy" page style to implement the FancyHdr headers
%% ---------------------------------------------------------------- 
\addtotoc{Abstract}  % Add the "Abstract" page entry to the Contents
\abstract{
	\addtocontents{toc}{\vspace{1em}}  % Add a gap in the Contents, for aesthetics

	In modern electronic devices, both consumer and industrial, wireless technology is quickly becoming a
	must-have feature; wireless Bluetooth technology is now standard in almost all mobile phones, laptops and
	other devices. However, despite its prevalence, Bluetooth as a technology remains too expensive and/or
	impractical to integrate into embedded products and systems which lack large amounts of processing power
	and memory.
	
	While some existing embedded Bluetooth stacks are available, these remain expensive, limited, and/or
	closed-source, which otherwise prevent their use in applications where Bluetooth technology would be
	both desired and applicable.
	
	To combat this deficiency in the marketplace, the aim of this project is to design and produce a free,
	open source, small footprint Bluetooth stack aimed to suit small embedded environments. This project will
	allow for Bluetooth technology to be directly integrated into small scale products at a low cost, while
	remaining fully functional and extensible.
}

\clearpage  % Abstract ended, start a new page
%% ----------------------------------------------------------------
\setstretch{1.3}  % Reset the line-spacing to 1.3 for body text (if it has changed)

% The Acknowledgements page, for thanking everyone
\acknowledgements{
	\addtocontents{toc}{\vspace{1em}}  % Add a gap in the Contents, for aesthetics
	
	Special thanks to Robert Ross for his 3D modeling contributions to the project, without which the project's
	final robot design would be all the poorer. Also thanks to Ben Rampling for his expert assistance in reviewing
	the first revision of the project schematics, and to Professor John Devlin for his role as the project's supervisor.
	
	Thank you to the wider AVR community for their interest and support for the project, and to Matt from
	\textit{\href{http://www.micropendous.org}{Opendous Inc.}} for his generous contribution of the free
	\textit{``Micropendous''} AVR microcontroller boards used in the final robot prototype.
}

\clearpage  % End of the Acknowledgements
%% ----------------------------------------------------------------
\pagestyle{fancy}  %The page style headers have been "empty" all this time, now use the "fancy" headers as defined before to bring them back
%% ----------------------------------------------------------------
\pdfbookmark[0]{Contents}{Contents}
\lhead{\emph{Contents}}  % Set the left side page header to "Contents"
\tableofcontents  % Write out the Table of Contents
%% ----------------------------------------------------------------
\lhead{\emph{List of Figures}}  % Set the left side page header to "List of Figures"
\listoffigures  % Write out the List of Figures
%% ----------------------------------------------------------------
\lhead{\emph{List of Tables}}  % Set the left side page header to "List of Tables"
\listoftables  % Write out the List of Tables
%% ----------------------------------------------------------------
\phantomsection
\addcontentsline{toc}{chapter}{List of Code Listings}
\lhead{\emph{List of Code Listings}}  % Set the left side page header to "List of Code Listings"
\renewcommand\lstlistlistingname{List of Code Listings}
\lstlistoflistings
%% ----------------------------------------------------------------
\mainmatter
\pagestyle{fancy}

	\input{./Chapters/Overview}
	\input{./Chapters/ExistingImplementations}
	\input{./Chapters/BluetoothStackImplementation}
	\input{./Chapters/RobotHWImplementation}
	\input{./Chapters/RobotFWImplementation}
	\input{./Chapters/Results}	
	\input{./Chapters/Discussion}
	\input{./Chapters/Conclusion}
%% ----------------------------------------------------------------
\setstretch{1.5}  % Set the line spacing to 1.5, this makes the following tables easier to read
\clearpage  % Start a new page
\lhead{\emph{Abbreviations}}  % Set the left side page header to "Abbreviations"
\listofsymbols{ll}  % Include a list of Abbreviations (a table of two columns)
{
	\textbf{API} & \textbf{A}pplication \textbf{P}rogramming \textbf{I}nterface \\
	\textbf{AVR} & This isn't an acronym. Officially, at least. \\
	\textbf{BDADDR} & \textbf{B}luetooth \textbf{D}evice \textbf{Addr}ess \\
	\textbf{CPU} & \textbf{C}entral \textbf{P}rocessing \textbf{U}nit \\
	\textbf{DC} & \textbf{D}irect \textbf{C}urrent \\
	\textbf{DRC} & \textbf{D}esign \textbf{R}ule \textbf{C}heck \\
	\textbf{EEPROM} & \textbf{E}lectrically \textbf{E}rasable \textbf{P}rogrammable \textbf{R}ead \textbf{O}nly \textbf{M}emory \\
	\textbf{EMF} & \textbf{E}lectro\textbf{m}otive \textbf{F}orce \\
	\textbf{FAT} & \textbf{F}ile \textbf{A}llocation \textbf{T}able \\
	\textbf{GPIO} & \textbf{G}eneral \textbf{P}urpose \textbf{I}nput/\textbf{O}utput \\
	\textbf{HCI} & \textbf{H}ost \textbf{C}ontroller \textbf{I}nterface \\
	\textbf{HID} & \textbf{H}uman \textbf{I}nterface \textbf{D}evice \\
	\textbf{IC} & \textbf{I}ntergrated \textbf{C}ircuit \\
	\textbf{I\textsuperscript{2}C} & \textbf{I}nter \textbf{I}ntegrated \textbf{C}ircuit Bus \\
	\textbf{IP} &  \textbf{I}ntellectual \textbf{P}roperty \\
	\textbf{JTAG} & \textbf{J}oint \textbf{T}est \textbf{A}ction \textbf{G}roup \\
	\textbf{L2CAP} & \textbf{L}ogical \textbf{L}ink \textbf{C}ontrol and \textbf{A}daption \textbf{P}rotocol \\
	\textbf{LCD} & \textbf{L}iquid \textbf{C}rystal \textbf{D}isplay \\
	\textbf{LDO} & \textbf{L}ow-\textbf{D}r\textbf{o}pout (Regulator) \\
	\textbf{LED} & \textbf{L}ight \textbf{E}mitting \textbf{D}iode \\
	\textbf{LUFA} & \textbf{L}ightweight \textbf{U}SB \textbf{F}ramework for \textbf{A}VRs \\
	\textbf{MAC} & \textbf{M}edia \textbf{A}ccess \textbf{C}ontrol \\
	\textbf{PC} & \textbf{P}ersonal \textbf{C}omputer \\
	\textbf{PCB} & \textbf{P}rinted \textbf{C}ircuit \textbf{B}oard \\
	\textbf{PLL} & \textbf{P}hase \textbf{L}ocked \textbf{L}oop \\
	\textbf{PWM} & \textbf{P}ulse \textbf{W}idth \textbf{M}odulation \\
	\textbf{RFCOMM} & \textbf{R}adio \textbf{F}requency \textbf{Comm}unication \\
	\textbf{RTOS} & \textbf{R}eal \textbf{T}ime \textbf{O}perating \textbf{S}ystem \\
	\textbf{SDP} & \textbf{S}ervice \textbf{D}iscovery \textbf{P}rotocol \\
	\textbf{SRAM} & \textbf{S}tatic \textbf{R}andom \textbf{A}ccess \textbf{M}emory \\
	\textbf{TCP/IP} & \textbf{T}ransmission \textbf{C}ontrol \textbf{P}rotocol / \textbf{I}nternet \textbf{P}rotocol \\
	\textbf{UART} & \textbf{U}niversal \textbf{A}synchronous \textbf{R}eceiver \textbf{T}ransmitter \\
	\textbf{UI} & \textbf{U}ser \textbf{I}nterface \\
	\textbf{USB} & \textbf{U}niversal \textbf{S}erial \textbf{B}us \\
	\textbf{UUID} & \textbf{U}niversally \textbf{U}nique \textbf{Id}entifier \\
}
%% ----------------------------------------------------------------
\addtocontents{toc}{\vspace{1em}} % Add a gap in the Contents, for aesthetics
\appendix % Cue to tell LaTeX that the following 'chapters' are Appendices

	\input{./Appendices/RobotUserGuide}
	\input{./Appendices/SourceCode}
	\input{./Appendices/Schematics}
	
\addtocontents{toc}{\vspace{2em}}  % Add a gap in the Contents, for aesthetics
\backmatter
%% ----------------------------------------------------------------
\label{Bibliography}
\lhead{\emph{Bibliography}}  % Change the left side page header to "Bibliography"
\bibliographystyle{unsrtnat}  % Use the "unsrtnat" BibTeX style for formatting the Bibliography
\bibliography{Thesis}  % The references (bibliography) information are stored in the file named "Bibliography.bib"
%% ----------------------------------------------------------------
\end{document}  % The End
